package com.hcy.controller.manager;

import com.hcy.driver.entity.CarLevel;
import com.hcy.manager.CarInfoBz;
import com.hcy.manager.DriverInfoBz;
import com.hcy.manager.dto.request.*;
import com.hcy.manager.dto.response.CarInfoResponseDTO;
import com.hcy.manager.dto.response.CarLevelResponseDTO;
import com.hcy.manager.dto.response.CarTypeResponseDTO;
import com.hcy.manager.dto.response.DriverInfoResponseDTO;
import com.hcy.rabbitbasicmodel.dto.MyPage;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.rabbitbasicmodel.signl.Add;
import com.hcy.rabbitbasicmodel.signl.Delete;
import com.hcy.rabbitbasicmodel.signl.Query;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/4/27
 **/
@RestController
@Slf4j
@RequestMapping("/managerCar")
public class CarManagerController {

    @Autowired
    private CarInfoBz carInfoBz;

    /**
     * @Author huchenying
     * @Description  获取车辆列表
     * @Date 2022/4/27 0:07
     **/
    @PostMapping("/getCarList")
    public ResponseData<MyPage<CarInfoResponseDTO>> getCarList(@Validated(Query.class) @RequestBody CarInfoRequestDTO requestDTO){
        log.info("getDriverList start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<MyPage<CarInfoResponseDTO>> responseData = new ResponseData<>();
        try {
            MyPage<CarInfoResponseDTO> responseDTOMyPage = carInfoBz.getCarList(requestDTO);
            return responseData.success(responseDTOMyPage);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("获取列表信息失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  更改车辆状态
     * @Date 2022/4/26 23:13
     **/
    @PostMapping("/updateCarStatus")
    public ResponseData<Object> updateCarStatus(@Validated(Delete.class) @RequestBody CarInfoRequestDTO requestDTO){
        log.info("deleteCar start param -> {}", ToStringBuilder.reflectionToString(requestDTO));
        try {
            carInfoBz.updateCarStatus(requestDTO);
            return ResponseData.success();
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return ResponseData.fail0("取消失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  插入或更新 车辆
     * @Date 2022/4/27 0:27
     **/
    @PostMapping("/insertOrUpdateCar")
    public ResponseData<CarInfoResponseDTO> insertOrUpdate(@Validated @RequestBody CarInfoAddRequestDTO requestDTO){
        log.info("insertOrUpdate start param -> {}",ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<CarInfoResponseDTO> responseData = new ResponseData<>();
        try {
            CarInfoResponseDTO responseDTO = carInfoBz.insertOrUpdate(requestDTO);
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("添加失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  获取车辆类型
     * @Date 2022/4/27 0:41
     **/
    @PostMapping("/getCarTypeList")
    public ResponseData<List<CarTypeResponseDTO>> getCarTypeList(){
        log.info("getCarTypeList start ");
        ResponseData<List<CarTypeResponseDTO>> responseData = new ResponseData<>();
        try {
            List<CarTypeResponseDTO> responseDTO = carInfoBz.getCarTypeList();
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("获取车辆类型列表失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  添加或更新 车辆类型
     * @Date 2022/4/27 0:41
     **/
    @PostMapping("/insertOrUpdateCarType")
    public ResponseData<CarTypeResponseDTO> insertOrUpdateCarType(@Validated(Add.class) @RequestBody CarTypeRequestDTO requestDTO){
        log.info("insertOrUpdateCarType start param -> {}",ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<CarTypeResponseDTO> responseData = new ResponseData<>();
        try {
            CarTypeResponseDTO responseDTO = carInfoBz.insertOrUpdateCarType(requestDTO);
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("添加失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  删除 车辆类型
     * @Date 2022/4/27 0:41
     **/
    @PostMapping("/deleteCarType")
    public ResponseData<Object> deleteCarType(@Validated(Delete.class) @RequestBody CarTypeRequestDTO requestDTO){
        log.info("deleteCarType start param -> {}",ToStringBuilder.reflectionToString(requestDTO));
        try {
            carInfoBz.deleteCarType(requestDTO);
            return ResponseData.success();
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return ResponseData.fail0("删除失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  获取车辆等级
     * @Date 2022/4/27 0:41
     **/
    @PostMapping("/getCarLevelList")
    public ResponseData<List<CarLevelResponseDTO>> getCarLevelList(){
        log.info("getCarTypeList start ");
        ResponseData<List<CarLevelResponseDTO>> responseData = new ResponseData<>();
        try {
            List<CarLevelResponseDTO> responseDTO = carInfoBz.getCarLevelList();
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("获取车辆等级列表失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  添加或更新 车辆等级
     * @Date 2022/4/27 0:41
     **/
    @PostMapping("/insertOrUpdateCarLevel")
    public ResponseData<CarLevelResponseDTO> insertOrUpdateCarLevel(@Validated(Add.class) @RequestBody CarLevelRequestDTO requestDTO){
        log.info("insertOrUpdateCarType start param -> {}",ToStringBuilder.reflectionToString(requestDTO));
        ResponseData<CarLevelResponseDTO> responseData = new ResponseData<>();
        try {
            CarLevelResponseDTO responseDTO = carInfoBz.insertOrUpdateCarLevel(requestDTO);
            return responseData.success(responseDTO);
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return responseData.fail("添加失败");
        }
    }

    /**
     * @Author huchenying
     * @Description  删除 车辆等级
     * @Date 2022/4/27 0:41
     **/
    @PostMapping("/deleteCarLevel")
    public ResponseData<Object> deleteCarLevel(@Validated(Delete.class) @RequestBody CarLevelRequestDTO requestDTO){
        log.info("deleteCarLevel start param -> {}",ToStringBuilder.reflectionToString(requestDTO));
        try {
            carInfoBz.deleteCarLevel(requestDTO);
            return ResponseData.success();
        } catch (Exception e) {
            log.error("e -> {}",ToStringBuilder.reflectionToString(e));
            return ResponseData.fail0("删除失败");
        }
    }


}
